import os

import pinia
from console_conpent.select import select
from effect.util.console.SuperConsole import cls, readKey, Anykey
from game.newGame import NewGame
from game.TopClass import Windows
from game_control.save.saveManager import SaveManager


class SelectSave(Windows):
    def UiShow(self):
        print("存档查看")
        dirs = os.listdir("./json/Save")
        if len(dirs) == 0:
            cls()
            print("暂无存档 按任意键新建存档...")
            Anykey()
            NewGame().UiShow()
        else:
            select_clsas = select(
                title="请选择你的存档",
                options=dirs,
                tips=["存档" for i in dirs],
            )
            select_clsas.show()
            saveName = select_clsas.getvalue()  # 获取存档
            saveManager = SaveManager()
            saveManager.loadSave(saveName)  # 加载存档
            pinia.store['savemanager'] = saveManager  # 全局化资源
            pinia.store['savename'] = saveName

    def Logic(self):
        ...
